package com.atlin.cli;

import com.atlin.cli.command.ConfigCommand;
import com.atlin.cli.command.GeneratorCommand;
import com.atlin.cli.command.ListCommand;
import picocli.CommandLine;
import picocli.CommandLine.Command;

/**
 * @author atlin
 * @description 命令执行器
 * @createDate 2024/9/23 13:56
 */
@Command(name = "linCodeGen", mixinStandardHelpOptions = true)
public class CommandExecutor implements Runnable {

    private final CommandLine commandLine;

    {
        commandLine = new CommandLine(this)
                .addSubcommand(new ListCommand())
                .addSubcommand(new GeneratorCommand())
                .addSubcommand(new ConfigCommand());
    }

    @Override
    public void run() {
        // 不输入子命令时候输出友好提示
        System.out.println("请输入具体命令，或者输入 --help 查看命令提示。");
    }


    /**
     * 执行命令
     *
     * @param args 命令参数
     * @return 退出码
     */
    public Integer doExecute(String[] args) {
        return commandLine.execute(args);
    }
}
